package com.woniuxy.purchasemanager.util;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;

import static org.apache.poi.ss.usermodel.BorderStyle.DASHED;

/**
 * @ClassName ExcelUtils
 * @Description 工具类
 * @Author xianhao
 * @Date 2022/4/21 14:10
 * @Version 1.0.0
 */
public class ExcelUtils {

    /**
     * 设置样式
     * @Author: xianhao
     * @Date: 2022/4/21 14:11
     * @return: com.alibaba.excel.write.style.HorizontalCellStyleStrategy
     **/
    public static final HorizontalCellStyleStrategy getHorizontalCellStyleStrategy() {
        //设置标题样式
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        //设置字体居中显示
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        //构造字体对象
        WriteFont writeFont = new WriteFont();
        writeFont.setFontHeightInPoints((short) 15);
        headWriteCellStyle.setWriteFont(writeFont);
        headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());

        //设置content样式
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        //设置字体垂直居中和水平居中
        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //设置字体大小
        writeFont.setFontHeightInPoints((short) 12);
        contentWriteCellStyle.setWriteFont(writeFont);
        //自动换行
        contentWriteCellStyle.setWrapped(true);

        //设置边框样式  DASHED虚线
        contentWriteCellStyle.setBorderLeft(DASHED);
        contentWriteCellStyle.setBorderTop(DASHED);
        contentWriteCellStyle.setBorderRight(DASHED);
        contentWriteCellStyle.setBorderBottom(DASHED);

        //水平单元格样式策略, 头是头的样式 内容是内容的样式 其他的策略可以自己实现
        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
    }
}
